ChannelManager read refactor follow ups#4374
ChannelManager read refactor follow ups#4374joostjager wants to merge 5 commits intolightningdevkit:mainfrom
Conversation
|
👋 Thanks for assigning @valentinewallace as a reviewer! |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4374 +/- ##
==========================================
+ Coverage 85.99% 86.02% +0.02%
==========================================
Files 156 156
Lines 102766 102844 +78
Branches 102766 102844 +78
==========================================
+ Hits 88378 88471 +93
+ Misses 11879 11863 -16
- Partials 2509 2510 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
valentinewallace
left a comment
There was a problem hiding this comment.
Care to throw in any of these mentioned updates? #4332 (comment) Seems like a good opportunity
lightning/src/ln/channelmanager.rs
Outdated
| testing_dnssec_proof_offer_resolution_override: Mutex::new(new_hash_map()), | ||
| }; | ||
|
|
||
| // Step 7: Replay pending claims and fail HTLCs. |
There was a problem hiding this comment.
In my experience using step numbers in ldk-sample main, it's kinda annoying to have to update all of them when something changes. Maybe that's not as much of a risk here
There was a problem hiding this comment.
I thought it might help a bit with navigation in this huge function. In other languages one would quickly extract methods, but in my experience that isn't always in Rust. Would you prefer that? I can try it.
There was a problem hiding this comment.
I wouldn't really prefer extracting methods. Just wanted to point it out, we can keep the numbers
There was a problem hiding this comment.
Made it unnumbered headings
|
👋 The first review has been submitted! Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer. |
13a8a3f to
b4429bb
Compare
Done |
valentinewallace
left a comment
There was a problem hiding this comment.
Nice cleanups here!
lightning/src/ln/channelmanager.rs
Outdated
| // consistency. Channels that are behind their monitors are force-closed. Channels without | ||
| // monitors (except those awaiting initial persistence) are rejected. Monitors without |
There was a problem hiding this comment.
I don't think it's true that channels without monitors will be rejected -- instead, we'll DecodeError::InvalidValue on the entire manager read. Were these comments added by Claude? I'm kinda not sold on them, they add to the review quite a bit and seem error prone/at risk of becoming out-of-date
There was a problem hiding this comment.
Yes, clauded indeed. Unfortunate. First I went and corrected them, but I also felt what you mention about becoming out-of-date. In my opinion, there aren't enough comments in the code base, but comments that are located a bit further away from the code aren't ideal. Dropped the commit.
lightning/src/ln/channelmanager.rs
Outdated
| async_receive_offer_cache: AsyncReceiveOfferCache, | ||
| // Marked `_legacy` because in versions > 0.2 we are taking steps to remove the requirement of | ||
| // regularly persisting the `ChannelManager` and instead rebuild the set of HTLC forwards from | ||
| // `Channel{Monitor}` data. See [`ChannelManager::read`]. |
There was a problem hiding this comment.
I don't think ChannelManager::read adds anything to the understanding of what's going on here, can probably remove that sentence
There was a problem hiding this comment.
Yes, this was pointing to the reconstruct boolean, but can't link that.
There was a problem hiding this comment.
Removed now, show references will get to the usage sites quickly enough. Can't link in // comments anyway.
lightning/src/ln/channelmanager.rs
Outdated
| .into_iter() | ||
| .zip(onion_fields) | ||
| .map(|((hash, htlcs), onion)| (hash, htlcs, onion)) | ||
| .collect() |
There was a problem hiding this comment.
Hmm, we introduce an intermediate allocation here. Wonder if the whole creation of claimable_payments can move here, to avoid it? It feels somewhat fitting.
There was a problem hiding this comment.
I've considered that, but it would need the keys for the legacy handling branch. But perhaps that's ok? The distinction between stage 1 and 2 isn't carved in stone.
There was a problem hiding this comment.
Updated the commit with this. It's seem better indeed.
| .unwrap_or_else(new_hash_map), | ||
| inbound_payment_id_secret, | ||
| in_flight_monitor_updates, | ||
| in_flight_monitor_updates: in_flight_monitor_updates.unwrap_or_default(), |
There was a problem hiding this comment.
Will this use HashMap::new() or new_hash_map (which I think is what we want)? CI seems fine though...
There was a problem hiding this comment.
I think it is the same?
HashMap::default() -> creates HashMap with RandomState::default() -> which calls RandomState::new() which is what new_hash_map does too?
There was a problem hiding this comment.
If true, we could replace all new_hash_map calls with HashMap::default(), to make it look slightly less custom.
Reorder the struct fields to place all three `_legacy` fields together at the end, allowing the explanatory comment to appear once instead of being duplicated three times. Co-Authored-By: Claude Opus 4.5 <[email protected]>
Initialize pending_claiming_payments and monitor_update_blocked_actions_per_peer with None and resolve with unwrap_or_else, matching the pattern used for other optional hash map fields like pending_intercepted_htlcs_legacy. Co-Authored-By: Claude Opus 4.5 <[email protected]>
Since there is no semantic difference between None and Some(empty vec) for peer_storage_dir, simplify the type to Vec and use unwrap_or_default() when reading from TLV fields. Co-Authored-By: Claude Opus 4.5 <[email protected]>
Move the reconstruction of claimable_payments from the main ChannelManager::read into ChannelManagerData::read. This removes the separate claimable_htlc_purposes and claimable_htlc_onion_fields fields from ChannelManagerData, replacing them with the combined claimable_payments HashMap. This requires adding a node_signer parameter to ChannelManagerDataReadArgs to support verification of legacy hop data when reconstructing payment purposes for very old serialized data (pre-0.0.107). Co-Authored-By: Claude Opus 4.5 <[email protected]>
Since there is no semantic difference between None and Some(empty map) for in_flight_monitor_updates, simplify the type to HashMap and use unwrap_or_default() when reading from TLV fields. Co-Authored-By: Claude Opus 4.5 <[email protected]>
b4429bb to
b509c4a
Compare
Followup commits to improve the readability and maintainability of the
ChannelManagerdeserialization code.